package demo.activity;

import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;
import android.widget.TextView;
import demo.expression.ExpressionUtil;
import demo.zandroid.R;

public class ZTestActivity extends Activity {

	private TextView tv_show1, tv_show2, tv_show3;
	private EditText edit;
	private ExpressionUtil expressionUtil;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_ztest);
		
		tv_show1 = (TextView) findViewById(R.id.tv_show1);
		tv_show2 = (TextView) findViewById(R.id.tv_show2);
		tv_show3 = (TextView) findViewById(R.id.tv_show3);
		
		
		edit = (EditText) findViewById(R.id.editText1);
		expressionUtil = ExpressionUtil.getInstance(ZTestActivity.this);
		edit.addTextChangedListener(new TextWatcher() {
			@Override
			public void onTextChanged(CharSequence s, int start, int before, int count) {
				
			}
			@Override
			public void beforeTextChanged(CharSequence s, int start, int count,
					int after) {
				
			}
			@Override
			public void afterTextChanged(Editable s) {
				tv_show1.setText(s);
				tv_show2.setText(s);
				tv_show3.setText(s);
				expressionUtil.setExpression(tv_show2);
				expressionUtil.setExpression(tv_show3);
				
				if(s.length() % 10 == 0){
					tv_show1.append("[[\r]]");
					tv_show2.append("[[\n]]");
					tv_show3.append("[[\r\n]]");
				}
			}
		});
	}
	
	@Override
	protected void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
	}
	
	@Override
	protected void onRestoreInstanceState(Bundle savedInstanceState) {
		super.onRestoreInstanceState(savedInstanceState);
	}
	
}
